{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=329
  Verdict: Accepted
}
uses SysUtils, Math;
 
type
	point=record
		x,y:longint;
		s:int64;
	end;
 
var
	i,n,kk:longint;
	s1,s2,s3:int64;
	s,nm,sn:string;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
for i:=1 to n do begin
	readln(S);
	kk:=pos(' ',s);
	nm:=copy(s,1,kk-1);
	delete(s,1,kk);  
	kk:=pos(' ',s);
	sn:=copy(s,1,kk-1);
	delete(s,1,kk);
	kk:=pos(' ',s);
	s1:=strtoint(copy(s,1,kk-1));
	delete(s,1,kk);
	kk:=pos(' ',s);
	s2:=strtoint(copy(s,1,kk-1));
	delete(s,1,kk);	
	kk:=pos(' ',s);
	if kk=0 then s3:=strtoint(s) else s3:=strtoint(copy(s,1,kk-1));
	if (s1>3) and (s2>3) and (s3>3) then writeln(nm,' ',sn);
end;
end.